<!DOCTYPE html>
<html lang="en">
<head>
    <script src="/static/js/dev.js"></script>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--bootstrap插件-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="/static/plugin/bootstrap/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/static/plugin/jo/joUI.css" rel="stylesheet"/>
    <!--字体插件-->
    <link href="/static/plugin/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/plugin/layui-2.4.3/css/layui.css" rel="stylesheet"/>
    <!--ztree-->
    <link href="/static/plugin/zTree/css/metroStyle/metroStyle.css" rel="stylesheet"/>
    <!--common-->
    <link href="/static/css/common.css" rel="stylesheet"/>
    <style>
        body .table > tbody > tr > td:last-child{
            overflow: visible;
        }
        .previewCode li a{
            padding-left: 10px;
            padding-right: 10px;
        }
    </style>
    <title>代码生成主体信息视图</title>
</head>
<body class="skin-default">

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12">

            <div class="container-fluid card">
                <div class="row">
                    <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
                        <!--检索栏-->
                        <form class="form-inline search-bar" id="pageForm">
                            <div class="form-group">
                                <label class="control-label">表名：&nbsp;</label>
                                <input type="text" name="tableName" class="form-control" value="">
                            </div>
                            <div class="form-group">
                                <label class="control-label">作者：&nbsp;</label>
                                <input type="text" name="author" class="form-control" value="">
                            </div>
                            <button type="button" class="btn btn-primary" onclick="joView.select()"><i
                                    class="fa fa-search" aria-hidden="true"></i>&nbsp;查询
                            </button>
                        </form>
                        <!--/检索栏-->
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
                        <!--按钮栏-->
                        <div class="form-group button-bar">
                            <button isShow="" type="button" class="btn btn-primary" onclick="joView.add()">
                                <i class="fa fa-plus" aria-hidden="true"></i>&nbsp;新建代码配置
                            </button>
                            <button isShow="" type="button" class="btn btn-success" onclick="exportConfig()">
                                <i class="fa fa-download" aria-hidden="true"></i>&nbsp;备份(导出配置)
                            </button>
                            <button isShow="" type="button" class="btn btn-info" onclick="importConfig()">
                                <i class="fa fa-upload" aria-hidden="true"></i>&nbsp;恢复(导入配置)
                            </button>
                            <button type="button" class="btn btn-danger" onclick="joView.del()">
                                <i class="fa fa-trash-o" aria-hidden="true"></i>&nbsp;删除
                            </button>
                            <button type="button" class="btn btn-warning" onclick="window.location.reload()">
                                <i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;刷新
                            </button>
                        </div>
                        <!--/按钮栏-->
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
                        <div class="table-bar">
                            <!--grid-->
                            <div class="table-responsive" style="overflow: visible;">
                                <table class="table table-bordered table-hover" id="mainList"
                                       dataUrl="{URL_CMS}cms/genMain/getPage" deleteUrl="{URL_CMS}cms/genMain/delete"
                                       formUrl="/page/cms/gen/genMainForm.html">
                                    <col field="tableName" title="表名" width="15%" align="left" headAlign="left"
                                         event="click"/>
                                    <col field="tableRemark" title="表说明" width="15%" align="left" headAlign="left"/>
                                    <col field="savePath" title="保存路径" width="25%" align="left" headAlign="left"/>
                                    <col field="name" title="备注" width="15%" align="left" headAlign="left"/>
                                    <col field="[=jo.formatTime('{createTime}')]" title="创建时间" width="15%" align=""/>
                                    <col field="_opt" title="操作" width="310px" align=""/>
                                </table>
                            </div>
                            <!--/grid-->

                            <!--分页条-->
                            <div class="page-bar" gridId="mainList">

                            </div>
                            <!--/分页条-->
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>


<!--配置信息-->
<script src="/static/js/config.js"></script>
<!--jquery-->
<script src="/static/plugin/jquery/jquery-3.3.1.js"></script>
<script src="/static/plugin/jquery/jquery.cookie.js"></script>
<!--bootstrap-->
<script src="/static/plugin/bootstrap/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="/static/plugin/other/html5shiv.js"></script>
<script src="/static/plugin/other/respond.min.js"></script>
<![endif]-->
<!--layui-->
<script src="/static/plugin/layui-2.4.3/layui.all.js"></script>
<!--ztree-->
<script src="/static/plugin/zTree/js/jquery.ztree.all.js"></script>
<!--上传插件-->
<link href="/static/plugin/webuploader-0.1.5/webuploader.css" rel="stylesheet">
<script src="/static/plugin/webuploader-0.1.5/webuploader.js"></script>
<script src="/static/js/upload.js"></script>
<!--common-->
<script src="/static/js/common.js"></script>
<!--jo-->
<script src="/static/plugin/jo/jo.js"></script>
<script src="/static/plugin/jo/jo-adapt.js"></script>
<script src="/static/plugin/jo/jo-page-view.js"></script>
<script src="/static/plugin/jo/jo-page-form.js"></script>
<script src="/static/plugin/jo/jo-listener.js"></script>
<script type="text/javascript">
    $(function () {
        joView.init({grid: $("#mainList"), PKName: "id", winRender: "top", formWidth: "85%"});//初始化页面
    });
    //行处理
    joView.handleItem = function (oItem, iIndex) {
        oItem._opt = '<button type="button" class="btn btn-sm btn-outline btn-primary" onclick="codeGenerate(\'' + oItem.id + '\')"> <i class="fa fa-magic" aria-hidden="true"></i>&nbsp;生成代码</button>';
        oItem._opt += '&nbsp;&nbsp;';
        oItem._opt += '<div class="btn-group previewCode" style="z-index: '+(1000-iIndex)+';">' +
            '<button type="button" class="btn btn-sm btn-success dropdown-toggle" data-toggle="dropdown">' +
            ' <i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;预览代码 <span class="caret"></span></button>' +
            '<ul class="dropdown-menu" role="menu" style="min-width: 5em;">' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'Controller\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;Controller</a></li>' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'Service\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;Service</a></li>' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'ServiceImpl\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;ServiceImpl</a></li>' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'Model\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;Model</a></li>' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'Mapper\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;Mapper</a></li>' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'List\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;页面-List</a></li>' +
            // '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'Form\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;页面-Form</a></li>' +
            '<li><a class="cursor-hand" onclick="previewCode(\'' + oItem.id + '\', \'Form_2\')"><i class="fa fa-file-text-o" aria-hidden="true"></i>&nbsp;页面-Form_2</a></li>' +
            '</ul>' +
            '</div>';
        oItem._opt += '&nbsp;&nbsp;';
        oItem._opt += '<button type="button" class="btn btn-sm btn-outline btn-info" onclick="createMenu(\'' + oItem.id + '\',\''+oItem.name+'\',\''+oItem.moduleName+'\',\''+oItem.className+'\')"> ' +
            '<i class="fa fa-chain" aria-hidden="true"></i>&nbsp;创建菜单</button>';

    };

    // 创建菜单
    function createMenu(genId, name, moduleName, className) {
        var link = '/page';
        if (moduleName) {
            link += '/' + moduleName;
        }
        if (className) {
            link += '/' + className.substring(0,1).toLowerCase() + className.substring(1) + 'List';
        }
        link += '.html';
        var _html = '<form id="createMenuForm" style="width: 100%;padding: 10px;">' +
                '<div class="young-form-item col-md-12 must">' +
                    '<div class="young-form-label">菜单名称</div>' +
                    '<div class="young-form-tips"></div>' +
                    '<div class="young-form-input-block">' +
                        '<input type="text" name="name" value="'+jo.getDefVal(name,'')+'" class="form-control "  ErrEmpty="菜单名称不允许为空" autocomplete="off"/>' +
                    '</div>' +
                '</div>' +
                '<div class="young-form-item col-md-12 must">' +
                    '<div class="young-form-label">菜单链接</div>' +
                    '<div class="young-form-tips"></div>' +
                    '<div class="young-form-input-block">' +
                        '<input type="text" name="href" value="'+jo.getDefVal(link,'')+'" class="form-control "  ErrEmpty="链接不允许为空" autocomplete="off"/>' +
                    '</div>' +
                '</div>' +
                '<div class="young-form-item col-md-12 must">' +
                    '<div class="young-form-label">上级菜单</div>' +
                    '<div class="young-form-tips"></div>' +
                    '<div class="young-form-input-block">' +
                        '<div class="input-group">' +
                            '<input type="hidden" id="parentId" name="parentId" class="form-control">' +
                            '<input type="text" id="parentName" value="ROOT" name="parentName" class="form-control" readonly>' +
                            '<span class="input-group-btn">' +
                                '<button class="btn btn-default" type="button" onclick="choiceNavigate(\'parentId\', \'parentName\', false)">' +
                                '<i class="fa fa-bars" aria-hidden="true"></i>&nbsp;选择' +
                                '</button>' +
                            '</span>' +
                        '</div>' +
                    '</div>' +
                '</div>' +

                '<div class="young-form-item col-md-12">' +
                    '<div class="young-form-label">菜单图标</div>' +
                    '<div class="young-form-tips"></div>' +
                    '<div class="young-form-input-block">' +
                        '<div class="input-group">' +
                            '<span id="iconShow" class="input-group-addon" style="width: 30px;"><i class="fa fa-th-list" aria-hidden="true"></i></span>' +
                            '<input type="text" id="icon" name="icon" value="fa-th-list" class="form-control">' +
                            '<span class="input-group-btn">' +
                            '<button class="btn btn-default" type="button" onclick="choiceIcon(\'icon\', iconSelectClick)">' +
                            '<i class="fa fa-bars" aria-hidden="true"></i>&nbsp;选择' +
                            '</button>' +
                            '</span>' +
                        '</div>' +
                    '</div>' +
                '</div>' +

                '<div class="young-form-item col-md-12">' +
                    '<div class="young-form-label">显示顺序</div>' +
                    '<div class="young-form-tips"></div>' +
                    '<div class="young-form-input-block">' +
                        '<input type="text" name="num" value="100" class="form-control "  autocomplete="off"/>' +
                    '</div>' +
                '</div>' +
            '</form>';
        jo.showDialog(_html, 'win_createMenu', true, {
            title: '创建菜单'
            , area: ['550px', '370px']
            , btn: ['保存', '取消']
            , btn1: function (idx) {
                jo.confirm('确定要创建嘛?', function (idx2) {
                    if (!jo.checkForm($('#createMenuForm'))) {
                        return;
                    }
                    var param = jo.form2Json('createMenuForm');
                    jo.close(idx2);
                    jo.postAjax('/cms/genMain/createMenu', param, function (json) {
                        if (json && json.code == '0') {
                            jo.showSuccessMsg('创建成功~');
                            jo.close(idx);
                        } else {
                            jo.showErrorMsg(jo.getDefVal(json.info, '创建失败~'));
                        }
                    }, true);
                });
            }
        });
    }

    //代码预览
    function previewCode(genId, type) {
        if (genId && type) {
            var url = '{URL_CMS}cms/genMain/preview/' + type + '/' + genId;
            jo.postAjax(url, {}, function (json) {
                if (json) {
                    var page = '/page/cms/codeEdit/mainCodeEdit.html';
                    if (type == 'List' || type == 'Form_2' || type == 'Mapper') {
                        page = '/page/cms/codeEdit/javaCodeShow.html';
                    }
                    var idx = jo.showWin(page, "900px", "500px", "预览代码");
                    var preWin = jo.getLayerIframe(idx);
                    jo.iframeLoaded(preWin, function(){
                        preWin.setContent(json);
                    });
                }
            });
        }
    }
    //图标选择
    function iconSelectClick(sClass){
        $("#icon").val(sClass);
        $("#iconShow").html('<i class="fa '+sClass+'" aria-hidden="true"></i>');
        jo.close();
    }

    //代码生成
    function codeGenerate(genId) {
        if (genId) {
            jo.postAjax("{URL_CMS}cms/genMain/generate/" + genId, {}, function (json) {
                if (json && json.code == 0) {
                    jo.showMsg("操作成功!", {icon: 1});
                }
            });
        }
    }

    //导出配置
    function exportConfig() {
        var ids = jo.getCheckBoxValue("id");
        if (!ids) {
            jo.showMsg("请先勾选待备份项!", {icon: 0});
            return;
        }
        jo.post("{URL_CMS}cms/genMain/backup", {ids: ids});
    }

    //导入配置
    function importConfig() {
        jo.uploadFile("{URL_CMS}cms/genMain/recover", function (success, file, json) {
            if (success && json.code == 0) {
                jo.showMsg("恢复成功!", {icon: 1});
            } else {
                jo.showMsg("操作失败!", {icon: 2});
            }
            jo.closeUploadDialog();
            joView.reloadCurrentPage();
        }, {UPLOAD_FILE_TYPES: 'gen', fileNumLimit: 1})
    }
</script>

</body>
</html>
